﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PMisuseAn.behaviour.model;
using System.Runtime.Serialization;

namespace PMisuseAn.behaviour.adaptation
{
    [Serializable()]
    public class AdaptationDescriptor : ISerializable
    {
        public List<Threat> threats;
        public  List<Attribute> threathenedOperationalAttributes;
        public  string adaptationAction;
        public  List<double> maxUtilityFunctions;
        public  List<double> sensitivity_level_utilitys;
        public  List<double> obf_level_utilitys;
        public  double sensitivity_level_constant;
        public  double obf_level_constant;
        public List<string> decisions;
        public string adaptationRule;
        public string metaAdaptationRule;
        public List<double> threatFrequencys;
        public List<List<string>> h_adaptationActionss;

        //Default constructor
        public AdaptationDescriptor(List<Threat> threats_,
            List<Attribute> threathenedOperationalAttributes_,
            string adaptationAction_,
            List<double> maxUtilityFunctions_,
            List<double> sensitivity_level_utilitys_,
            List<double> obf_level_utilitys_,
            double sensitivity_level_constant_,
            double obf_level_constant_,
            List<string> decisions_,
            string adaptationRule_,
            string metaAdaptationRule_,
            List<double> threatFrequencys_,
            List<List<string>> h_adaptationActionss_)
        {
            threats = threats_;
            threathenedOperationalAttributes = threathenedOperationalAttributes_;
            adaptationAction = adaptationAction_;
            maxUtilityFunctions = maxUtilityFunctions_;
            sensitivity_level_utilitys = sensitivity_level_utilitys_;
            obf_level_utilitys = obf_level_utilitys_;
            sensitivity_level_constant = sensitivity_level_constant_;
            obf_level_constant = obf_level_constant_;
            decisions = decisions_;
            adaptationRule = adaptationRule_;
            metaAdaptationRule = metaAdaptationRule_;
            threatFrequencys = threatFrequencys_;
            h_adaptationActionss = h_adaptationActionss_;
            
        }

        //Deserialization constructor.
        public AdaptationDescriptor(SerializationInfo info, StreamingContext ctxt)
        {
            //Get the values from info and assign them to the appropriate properties
            threats = (List<Threat>)info.GetValue("threat", typeof(List<Threat>));
            threathenedOperationalAttributes = (List<Attribute>)info.GetValue("threathenedOperationalAttributes", typeof(List<Attribute>));
            adaptationAction = (string)info.GetValue("adaptationAction", typeof(string));
            maxUtilityFunctions = (List<double>)info.GetValue("maxUtilityFunctions", typeof(List<double>));
            sensitivity_level_utilitys = (List<double>)info.GetValue("sensitivity_level_utilitys", typeof(List<double>));
            obf_level_utilitys = (List<double>)info.GetValue("obf_level_utilitys", typeof(List<double>));
            sensitivity_level_constant = (double)info.GetValue("sensitivity_level_constant", typeof(double));
            obf_level_constant = (double)info.GetValue("obf_level_constant", typeof(double));
            decisions = (List<string>)info.GetValue("decisions", typeof(List<string>));
            adaptationRule = (string)info.GetValue("adaptationRule", typeof(string));
            metaAdaptationRule = (string)info.GetValue("metaAdaptationRule", typeof(string));
            threatFrequencys = (List<double>)info.GetValue("threatFrequencys", typeof(List<double>));
            h_adaptationActionss = (List<List<string>>)info.GetValue("h_adaptationActionss", typeof(List<List<string>>));
        }
        
        //Serialization function.
        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("threats", threats);
            info.AddValue("threathenedOperationalAttributes", threathenedOperationalAttributes);
            info.AddValue("adaptationAction", adaptationAction);
            info.AddValue("maxUtilityFunctions", maxUtilityFunctions);
            info.AddValue("sensitivity_level_utilitys", sensitivity_level_utilitys);
            info.AddValue("obf_level_utilitys", obf_level_utilitys);
            info.AddValue("sensitivity_level_constant", sensitivity_level_constant);
            info.AddValue("obf_level_constant", obf_level_constant);
            info.AddValue("decisions", decisions);
            info.AddValue("adaptationRule", adaptationRule);
            info.AddValue("metaAdaptationRule", metaAdaptationRule);
            info.AddValue("threatFrequencys", threatFrequencys);
            info.AddValue("h_adaptationActionss", h_adaptationActionss);
        }

    }
}
